package com.schedule.controller;

import com.schedule.Util.PagedGridResult;
import com.schedule.pojo.Player;
import com.schedule.pojo.Player1;
import com.schedule.pojo.RespBean;
import com.schedule.service.IPlayCompetitionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/playcompetition")
public class PlayCompetitionController {

    @Autowired
    private IPlayCompetitionService playCompetitionService;

    /**
     //     * 根据选手的ID查找该选手参加的比赛及分数
     //     */
    @ApiOperation("根据选手的ID查找该选手参加的比赛及分数")
    @GetMapping("/getID/{pid}")
    @ResponseBody
    public RespBean findCompetitionByPid(@PathVariable(value = "pid")Integer pid){  //获得选手参加的所有比赛
        List<Player1> players = playCompetitionService.findCompetitionByPid(pid);
        if (players != null){
            return RespBean.success("查询选手信息成功", players);
        }
        return RespBean.error("查询选手信息失败");
    }

    /**
     * 前端需注意该分页是通过比赛数进行的分页，而不是单个的人
     */
    @ApiOperation("查找所有选手参加的比赛及分数")
    @GetMapping("/findAll")
    @ResponseBody
    public RespBean findCompetitionAll(@RequestParam(name="page") Integer page,
                                       @RequestParam(name="pageSize") Integer pageSize){  //获得选手参加的所有比赛
        PagedGridResult gridResult = playCompetitionService.findAll(page, pageSize);
        if (gridResult != null){
            return RespBean.success("查询选手信息成功", gridResult);
        }
        return RespBean.error("查询选手信息失败");
    }

    @ApiOperation("通过比赛查找选手及分数")
    @GetMapping("/findAllByCompetition")
    @ResponseBody
    public RespBean findAllByCompetition(@RequestParam(name="page") Integer page,
                                       @RequestParam(name="pageSize") Integer pageSize){  //获得选手参加的所有比赛
        PagedGridResult gridResult = playCompetitionService.findAllByCompetition(page, pageSize);
        if (gridResult != null){
            return RespBean.success("查询选手信息成功", gridResult);
        }
        return RespBean.error("查询选手信息失败");
    }

}
